import java.util.InputMismatchException;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
/**
 * 修改员工信息
 */
public class Modify {
    public static  void modify(List<Map<String, Object>> em, String instruction) {
        System.out.println("请选择你要修改信息对应的员工编号");
        Scanner scanner = new Scanner(System.in);
        String id = scanner.nextLine();
        try {
            for (Map<String, Object> map : em) {
                if (id.equals(map.get("id").toString())) {
                    System.out.print("请选择你要修改的信息：");
                    System.out.println("1. 姓名 2. 年龄 3. 职位 4. 工资 5. 入职时间 6.员工编号");
                    String choice = scanner.nextLine();
                    switch (choice) {
                        case "1":
                            System.out.print("请输入新的姓名：");
                            String name = scanner.nextLine();
                            map.put("name", name);
                            System.out.println("修改成功");
                            break;
                        case "2":
                            System.out.print("请输入新的年龄：");
                            int age = Integer.parseInt(scanner.nextLine());
                            map.put("age", age);
                            System.out.println("修改成功");
                            break;
                        case "3":
                            System.out.print("请输入新的职位：");
                            String job = scanner.nextLine();
                            map.put("job", job);
                            System.out.println("修改成功");
                            break;
                        case "4":
                            System.out.print("请输入新的工资：");
                            double salary = Double.parseDouble(scanner.nextLine());
                            map.put("salary", salary);
                            System.out.println("修改成功");
                            break;
                        case "5":
                            System.out.print("请输入新的入职时间：");
                            String time = scanner.nextLine();
                            map.put("time", time);
                            System.out.println("修改成功");
                            break;
                        case "6":
                            System.out.print("请输入新的员工编号：");
                            String id1 = scanner.nextLine();
                            if (id1.equals(map.get("id").toString())) {
                                System.out.println("员工编号不能重复");
                            } else {
                                map.put("id", id1);
                                System.out.println("修改成功");
                            }
                    }
                }
            }
        } catch (InputMismatchException e) {
            e.printStackTrace();
            System.out.println("没有找到该编号的员工");
        }
        System.out.println("修改完成");
        System.out.println("-----员工信息表-----");
        for (Map<String, Object> map : em) {
            System.out.println(map);
        }
        System.out.println("-------------------");
    }
}
